package com.lovo.ssc.interceptor;

import com.lovo.ssc.bean.SysUser;
import com.lovo.ssc.service.ILevelService;
import com.lovo.ssc.service.ISysUserService;
import com.lovo.ssc.vo.UserVo;
import com.lovo.util.Verifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author WXL
 * @date 2022/7/8
 */
public class CartInterceptor implements HandlerInterceptor {

    @Autowired
    private ILevelService service;

    public static ThreadLocal<UserVo> thread = new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        UserVo userVo = new UserVo();
        SysUser sysUser =(SysUser) request.getSession().getAttribute("loginUser");
//        float discount = service.findDiscount(sysUser.getUserName());
//        System.out.println(discount);
        if (sysUser != null) {
            userVo.setUserId(sysUser.getUserId());
            userVo.setUserName(sysUser.getUserName());
            userVo.setUserFreeze(sysUser.getUserFreeze());
            userVo.setDepositMoney(sysUser.getDepositMoney());
            userVo.setUserPermissions(sysUser.getUserPermissions());
            userVo.setUserDiscount(sysUser.getUserDiscount());
            thread.set(userVo);
            return true;
        }
        return false;
    }


}
